package emulator.hardware.bits;

public class BitCollector {
	SharedBit target_bit;
	boolean[] source_bits;
	BitCollectorStrategy bit_strategy;
	
	public BitCollector(int in_cnt, SharedBit target, BitCollectorStrategy strategy)
	{
		source_bits = new boolean[in_cnt];
		target_bit = target;
		bit_strategy = strategy;
		updateTarget();
	}

	private void updateTarget() {
		target_bit.setValue(bit_strategy.evaluate(source_bits));
	}
	
	public void setBit(int index, boolean value)
	{
		source_bits[index] = value;
		updateTarget();
	}
	
	public SharedBit getBitAt(int index)
	{
		return new SharedCollectorBit(this, index);
	}
}
